home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / dtdts / datatyping.c.z / datatyping.c
Encoding:
C/C++ Source or Header  |  2003-11-18  |  4.0 KB  |  140 lines

  1. /*
  2.  * datatyping.c
  3.  *
  4.  * Copyright 2000, Silicon Graphics, Inc.
  5.  * ALL RIGHTS RESERVED
  6.  * 
  7.  * UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8.  * States.   Use of a copyright notice is precautionary only and does not
  9.  * imply publication or disclosure.
  10.  *
  11.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12.  * Use, duplication or disclosure by the Government is subject to restrictions
  13.  * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14.  * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15.  * in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16.  * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17.  * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18.  *
  19.  * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20.  * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21.  * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22.  * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23.  * GRAPHICS, INC.
  24.  */
  25. /* $XConsortium: datatyping.c /main/cde1_maint/1 1995/07/17 16:44:18 drk $ */
  26. /*
  27.  * (c) Copyright 1993, 1994 Hewlett-Packard Company
  28.  * (c) Copyright 1993, 1994 International Business Machines Corp.
  29.  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  30.  * (c) Copyright 1993, 1994 Novell, Inc.
  31.  */
  32.  
  33. #include <Xm/Form.h>
  34. #include <Xm/Text.h>
  35. #include <Dt/Dts.h>
  36.  
  37. #define ApplicationClass "DtDatatyping"
  38.  
  39. static Widget text;
  40.  
  41. static void DisplayTypeInfo(int, char**);
  42.  
  43. int main(int argc, char **argv)
  44. {
  45.     XtAppContext appContext;
  46.     Widget toplevel, form;
  47.     Arg args[20];
  48.     int n;
  49.  
  50.     toplevel = XtAppInitialize(&appContext, ApplicationClass, NULL, 0,
  51.                          &argc, argv, NULL, NULL, 0);
  52.  
  53.     if (argc == 1) {
  54.     printf("%s: No files specified.\n", argv[0]);
  55.     exit(1);
  56.     }
  57.  
  58.     form = XmCreateForm(toplevel, "form", NULL, 0);
  59.     XtManageChild(form);
  60.     n = 0;
  61.     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  62.     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  63.     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  64.     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  65.     XtSetArg(args[n], XmNeditable, False); n++;
  66.     XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  67.     XtSetArg(args[n], XmNrows, 25); n++;
  68.     XtSetArg(args[n], XmNcolumns, 90); n++;
  69.     text = XmCreateScrolledText(form, "text", args, n);
  70.     XtManageChild(text);
  71.  
  72.     XtRealizeWidget(toplevel);
  73.  
  74.     if (DtAppInitialize(appContext, XtDisplay(toplevel), toplevel, argv[0],
  75.                         ApplicationClass) == False) {
  76.         printf("%s: Couldn't initialize Dt\n", argv[0]);
  77.         exit(1);
  78.     }
  79.  
  80.     DtDbLoad();
  81.  
  82.     DisplayTypeInfo(argc, argv);
  83.  
  84.     XtAppMainLoop(appContext);
  85. }
  86.  
  87. static void DisplayTypeInfo(int argc, char **argv)
  88. {
  89.     char *file;
  90.     char *datatype;
  91.     char *icon;
  92.     char *actions;
  93.     char str[100];
  94.     int i;
  95.  
  96.     sprintf(str, "%-30s\t%-10s\t%-8s\t%-20s\n",
  97.             "File",
  98.             "DataType",
  99.             "Icon",
  100.             "Actions");
  101.     XmTextInsert(text, XmTextGetLastPosition(text), str);
  102.  
  103.     sprintf(str, "%-30s\t%-10s\t%-8s\t%-20s\n",
  104.             "-------------------",
  105.             "--------",
  106.             "----",
  107.             "-------");
  108.     XmTextInsert(text, XmTextGetLastPosition(text), str);
  109.  
  110.     for(i=1; i < argc; i++) {
  111.     char *file = argv[i];
  112.  
  113.         /* find out the Dts data type */
  114.         datatype = DtDtsFileToDataType(file);
  115.  
  116.         if(datatype) {
  117.         /* find the icon attribute for the data type */
  118.         icon = DtDtsDataTypeToAttributeValue(datatype, DtDTS_DA_ICON, file);
  119.         }
  120.  
  121.         /*  Directly find the action attribute for a file */
  122.  
  123.         actions = DtDtsFileToAttributeValue(file, DtDTS_DA_ACTION_LIST);
  124.         
  125.         sprintf(str, "%-30s\t%-10s\t%-8s\t%s\n",
  126.             file,
  127.             datatype?datatype:"unknown",
  128.             icon?icon:"unknown",
  129.             actions?actions:"unknown");
  130.     XmTextInsert(text, XmTextGetLastPosition(text), str);
  131.  
  132.     /* Free the space allocated by Dts */
  133.  
  134.         DtDtsFreeAttributeValue(icon);
  135.         DtDtsFreeAttributeValue(actions);
  136.         DtDtsFreeDataType(datatype);
  137.     }
  138. }
  139.  
  140.